package com.retail.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.retail.common.log.annotation.Log;
import com.retail.common.log.enums.BusinessType;
import com.retail.common.security.annotation.RequiresPermissions;
import com.retail.product.common.domain.TProduct;
import com.retail.product.service.ITProductService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;
import com.retail.common.core.utils.poi.ExcelUtil;
import com.retail.common.core.web.page.TableDataInfo;

/**
 * 商品服务Controller
 * 
 * @author retail
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/product")
public class TProductController extends BaseController
{
    @Autowired
    private ITProductService tProductService;

    /**
     * 查询商品服务列表
     */
    @RequiresPermissions("product:product:list")
    @GetMapping("/list")
    public TableDataInfo list(TProduct tProduct)
    {
        startPage();
        List<TProduct> list = tProductService.selectTProductList(tProduct);
        return getDataTable(list);
    }

    /**
     * 导出商品服务列表
     */
    @RequiresPermissions("product:product:export")
    @Log(title = "商品服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProduct tProduct)
    {
        List<TProduct> list = tProductService.selectTProductList(tProduct);
        ExcelUtil<TProduct> util = new ExcelUtil<TProduct>(TProduct.class);
        util.exportExcel(response, list, "商品服务数据");
    }

    /**
     * 获取商品服务详细信息
     */
    @RequiresPermissions("product:product:query")
    @GetMapping(value = "/{productId}")
    public Result getInfo(@PathVariable("productId") Integer productId)
    {
        return success(tProductService.selectTProductByProductId(productId));
    }

    /**
     * 新增商品服务
     */
    @RequiresPermissions("product:product:add")
    @Log(title = "商品服务", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody TProduct tProduct)
    {
        return toAjax(tProductService.insertTProduct(tProduct));
    }

    /**
     * 修改商品服务
     */
    @RequiresPermissions("product:product:edit")
    @Log(title = "商品服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody TProduct tProduct)
    {
        return toAjax(tProductService.updateTProduct(tProduct));
    }

    /**
     * 删除商品服务
     */
    @RequiresPermissions("product:product:remove")
    @Log(title = "商品服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public Result remove(@PathVariable Integer[] productIds)
    {
        return toAjax(tProductService.deleteTProductByProductIds(productIds));
    }
}
